import { Injectable } from '@angular/core';
import { LocalizationService } from '@abp/ng.core';
import { NzModalRef, NzModalService } from 'ng-zorro-antd/modal';
import { AuxiliaryUnitDto } from '../../proxy/joy/erp/basic-archives/item-masters';
import { UnitGroupRefChildrenSelectComponent } from './unit-group-ref-children-select.component';

@Injectable({
  providedIn: 'root',
})
export class UnitGroupRefChildrenSelectService {
  private defaultTitle: string = 'BasicArchives::UI:SimplyRefSelect.Title';
  private entityName: string = 'BasicArchives::ModelTitle:Joy.Erp.BasicArchives.ItemMasters.AuxiliaryUnit';
  private defaultWidth: number = 880;

  constructor(
    private modalService: NzModalService,
    private localizationService: LocalizationService
  ) {}

  show(defaultSelectedItems?: AuxiliaryUnitDto[], options?: { title?: string; width?: number; multiple?: boolean; unitGroupId?: string }): NzModalRef<UnitGroupRefChildrenSelectComponent, any> {
    var nzTitle = !options?.title ? this.l(this.defaultTitle, this.l(this.entityName)) : options.title;
    var nzWidth = !options?.width ? this.defaultWidth : options.width;

    let modalRef = this.modalService.create({
      nzTitle: nzTitle,
      nzMaskClosable: false,
      nzKeyboard: true,
      nzWidth: nzWidth,
      nzComponentParams: {
        selectedModels: defaultSelectedItems || [],
        multiple: options?.multiple ?? true,
        unitGroupId: options?.unitGroupId
      },
      nzContent: UnitGroupRefChildrenSelectComponent,
    });

    return modalRef;
  }

  protected l(key: string, ...parmas: string[]): string {
    return this.localizationService.instant(key, ...parmas);
  }
} 